package com.sunmouse.toolkit.fragment.other;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sunmouse.toolkit.R;
import com.sunmouse.toolkit.adapter.FunAdapter;
import com.sunmouse.toolkit.bean.PageBean;
import com.sunmouse.toolkit.fragment.BaseFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class ProviderFragment extends BaseFragment {

    @BindView(R.id.m_list)
    RecyclerView mList;
    Unbinder unbinder;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_list, container, false);
        unbinder = ButterKnife.bind(this, v);
        return v;
    }

    @Override
    public void init() {
        this.mData = new ArrayList<>();
        this.mAdapter = new FunAdapter(mData, getActivity());
        this.mList.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.mList.setAdapter(mAdapter);
        this.mAdapter.setOnChildClickListener(this);

        loadingData(1);

    }


    @Override
    public void loadingData(int page) {

        this.mData.add(new PageBean(1, "choose media"));
        this.mData.add(new PageBean(2, "choose photo"));
        this.mData.add(new PageBean(3, "choose audio"));
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onClick(View v, int position) {
        PageBean bean = mData.get(position);
        if (bean.getId()==1){
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("video/*");//设置类型，我这里是任意类型，任意后缀的可以这样写。
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            Intent wrapIntent = Intent.createChooser(intent, null);
            startActivityForResult(wrapIntent, 5);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


}
